﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Koonsoft.HYCRM.BLL;
using Koonsoft.HYCRM.Model;
using Koonsoft.HYCRM.Model.Enum;

public partial class Register_Register : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {


        EmpolyeeInfo empolyee = new EmpolyeeInfo();
        empolyee.Expansion = new EmpolyeeInfoExpansion();
        empolyee.Name = txtUserName.Text.Trim();
        empolyee.LoginName = txtLoginName.Text.Trim();
        empolyee.Password = txtLoginPassword.Text.Trim();
        empolyee.Status = (int)EmpolyeeStatus.Create;
        empolyee.Expansion.Address = txtUserAddress.Text.Trim();

        try
        {
            empolyee.Expansion.Birthday = DateTime.Parse(txtUserBirthday.Text.Trim());
        }
        catch (Exception)
        {
            AlertMsg("生日格式错误");
            return;
        }
        empolyee.Expansion.IdCard = txtUserIdCard.Text.Trim();
        empolyee.Expansion.Phone = txtUserPhone.Text.Trim();
        empolyee.Expansion.Sex = Convert.ToInt32(DropDownList1.SelectedValue);

        try
        {
            empolyee.EntryTime = DateTime.Parse(txtEntryTime.Text.Trim());
        }
        catch (Exception)
        {
            AlertMsg("入职时间式错误");
            return;
        }

        if (new EmpolyeeBLL().GetEmpolyeeInfoByLoginName(empolyee.LoginName) != null)
        {
            AlertMsg("登录名已存在，请选更改登录名");
            return;
        }

        try
        {
            if (new EmpolyeeBLL().AddNewEmpolyee(empolyee))
            {
                AlterAndRedirect("用户注册成功", "../default.aspx");
            }
            else
            {
                AlertMsg("注册失败，请联系管理员");
            }
        }
        catch (Exception ex)
        {
            AlertMsg(ex.Message);
        }
    }
}